package be.technofutur.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		SimpleDateFormat dateFormat = new SimpleDateFormat("EEEEE dd MMMMM yyyy");
		SimpleDateFormat timeFormat = new SimpleDateFormat("hh : mm : ss");
		Date now = new Date();
		String formatteDate = dateFormat.format(now);
		String formatteTime = timeFormat.format(now);
		String username = request.getParameter("username");
		if (username== null || username.isEmpty())
			/*username = " world" ;*/
		response.sendRedirect("http://www.google.be");
		out.println("<html><head><title>Hello Servlet !</title></head>");
		out.println("<body><h1>Hello "+ username+"</h1>");
		out.println("<p>Nous sommes le : "+ formatteDate + "</p>");
		out.println("<p>Il est : "+ formatteTime + "</p>");
		out.println("</body></html>");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet (request,response);
	}

}
